package com.xsjiong.jaript.lexer;

public class JLexerException extends Exception {
	public static final int INVALID_IDENTIFIER = 0, UNRECOGNIZED_CHAR = 1, ILLEGAL_ESCAPE_CHAR = 2;

	private int Type;
	private int Index;
	private Object Data;

	public JLexerException(int type) {
		this(type, -1, null);
	}

	public JLexerException(int type, int index) {
		this(type, index, null);
	}

	public JLexerException(int type, int index, Object data) {
		this.Type = type;
		this.Index = index;
		this.Data = data;
	}

	public int getType() {
		return Type;
	}

	@Override
	public String getMessage() {
		switch (Type) {
			case INVALID_IDENTIFIER:
				return "非法的标识符位于" + Index;
			case UNRECOGNIZED_CHAR:
				return "不可识别的字符位于" + Index + ": " + (int) Data;
			case ILLEGAL_ESCAPE_CHAR:
				return "非法的转义字符位于" + Index + ": " + (int) Data;
		}
		return null;
	}
}
